package com.linkage.educloud.ah.view.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.widget.FrameLayout;

import com.linkage.educloud.ah.R;
import com.linkage.educloud.ah.config.AppConfig;
import com.linkage.educloud.ah.view.BasicActivity;
import com.linkage.educloud.ah.view.fragment.GuideFragment;
import com.linkage.educloud.ah.view.fragment.SplashFragment;

import butterknife.BindView;

/**
 * <desc>
 * Created by The Moss on 2018/8/6.
 */

public class LuncherActivity extends BasicActivity {
    @BindView(R.id.fragment_content)
    FrameLayout fragmentContent;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_luncher;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        mManager.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
//            @Override
//            public void onBackStackChanged() {
//                Fragment fragment = mManager.findFragmentByTag("splash");
//                if (fragment != null) {
//                    fragment.onResume();
//                }
//            }
//        });
        initFragment();
    }
    private void initFragment(){
        boolean isGuide = AppConfig.getInstance().getBoolean(AppConfig.ShareKey.KEY_GUIDE, true);
        if (isGuide) {
            AppConfig.getInstance().putBoolean(AppConfig.ShareKey.KEY_GUIDE, false);
            mTransaction.add(R.id.fragment_content,GuideFragment.newInstance(),"guide")
//                .addToBackStack(SplashFragment.class.getSimpleName())
                    .commit();
        }else{
            mTransaction.add(R.id.fragment_content,SplashFragment.newInstance(),"splash")
//                .addToBackStack(SplashFragment.class.getSimpleName())
                    .commit();
        }

    }
    @Override
    public void onBackPressed() {
        Fragment fragment = mManager.findFragmentById(R.id.fragment_content);
        if (fragment instanceof GuideFragment) {
            if (((GuideFragment) fragment).onBackPressed()) {
                return;
            }
        }
        super.onBackPressed();
    }
}
